package 牛客网_N.动态规划.年终奖_11;

import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int m = Integer.parseInt(in.nextLine());
		int n = Integer.parseInt(in.nextLine());
		int[][] grid = new int[m][n];
		for(int i = 0; i < m; i++){
			String str = in.nextLine();
			String[] dataStr = str.split(" ");
			for(int j = 0; j < n; j++){
				grid[i][j] = Integer.parseInt(dataStr[j]);
			}
		}
		in.close();
		System.out.println(getMost(grid));
	}
	
	public static int getMost(int[][] board){
		int[][] res = new int[board.length][board[0].length];
		res[0][0] = board[0][0];
		for(int i = 1; i < board.length; i++){
			res[i][0] = res[i-1][0]+board[i][0];
		}
		for(int i = 1; i < board[0].length; i++){
			res[0][i] = res[0][i-1]+board[0][i];
		}
		for(int i = 1; i < board.length; i++){
			for(int j = 1; j < board[0].length; j++){
				res[i][j] = Math.max(res[i-1][j], res[i][j-1])+board[i][j];
			}
		}
		return res[board.length-1][board[0].length-1];
	}
}
